package radix

import (
	"regexp"

	"gitee.com/zengxinqian/hall"
)

type nodeType uint8

type nodeWildcard[Req any, Resp any] struct {
	path     string
	paramKey string
	handler  hall.Handler[Req, Resp]
}

type node[Req any, Resp any] struct {
	nType nodeType

	path         string
	tsr          bool
	handler      hall.Handler[Req, Resp]
	hasWildChild bool
	children     []*node[Req, Resp]
	wildcard     *nodeWildcard[Req, Resp]

	paramKeys  []string
	paramRegex *regexp.Regexp
}

type wildPath struct {
	path  string
	keys  []string
	start int
	end   int
	pType nodeType

	pattern string
	regex   *regexp.Regexp
}

// Tree is a routes storage
type Tree[Req any, Resp any] struct {
	root *node[Req, Resp]

	// If enabled, the node handler could be updated
	Mutable bool
}
